package class_object;

// 1. 简单枚举
enum Season {
    SPRING, SUMMER, AUTUMN, WINTER
}

// 2. 带属性和方法的枚举
enum Weekday {
    // 枚举常量，必须放在第一行
    MONDAY("星期一", 1),
    TUESDAY("星期二", 2),
    WEDNESDAY("星期三", 3),
    THURSDAY("星期四", 4),
    FRIDAY("星期五", 5),
    SATURDAY("星期六", 6),
    SUNDAY("星期日", 7);

    // 枚举属性
    private final String chineseName;
    private final int dayOfWeek;

    // 枚举构造方法（必须私有）
    private Weekday(String chineseName, int dayOfWeek) {
        this.chineseName = chineseName;
        this.dayOfWeek = dayOfWeek;
    }

    // 枚举方法
    public String getChineseName() {
        return chineseName;
    }

    public int getDayOfWeek() {
        return dayOfWeek;
    }

    // 判断是否为工作日
    public boolean isWeekday() {
        return this != SATURDAY && this != SUNDAY;
    }
}

public class EnumDemo {
    public static void main(String[] args) {
        // 使用简单枚举
        Season currentSeason = Season.SUMMER;
        System.out.println("当前季节：" + currentSeason);

        // 枚举switch语句
        switch (currentSeason) {
            case SPRING:
                System.out.println("春暖花开");
                break;
            case SUMMER:
                System.out.println("夏日炎炎");
                break;
            case AUTUMN:
                System.out.println("秋高气爽");
                break;
            case WINTER:
                System.out.println("冬雪纷飞");
                break;
        }

        // 使用带属性的枚举
        Weekday today = Weekday.FRIDAY;
        System.out.println("\n今天是" + today.getChineseName());
        System.out.println("是工作日吗？" + today.isWeekday());

        // 遍历所有枚举常量
        System.out.println("\n所有星期：");
        for (Weekday day : Weekday.values()) {
            System.out.println(day + " - " + day.getChineseName());
        }

        // 枚举常量的序号（从0开始）
        System.out.println("\n" + today + "的序号：" + today.ordinal());
    }
}
